package com.ruoyi.project.mydy.orderrecord.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mydy.orderrecord.domain.DlOrderRecord;
import com.ruoyi.project.mydy.orderrecord.service.IDlOrderRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 订单记录Controller
 * 
 * @author mhg
 * @date 2021-10-07
 */
@Controller
@RequestMapping("/mydy/orderrecord")
public class DlOrderRecordController extends BaseController
{
    private String prefix = "mydy/orderrecord";

    @Autowired
    private IDlOrderRecordService dlOrderRecordService;

    @RequiresPermissions("mydy:orderrecord:view")
    @GetMapping()
    public String orderrecord()
    {
        return prefix + "/orderrecord";
    }

    /**
     * 查询订单记录列表
     */
    @RequiresPermissions("mydy:orderrecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DlOrderRecord dlOrderRecord)
    {
        startPage();
        List<DlOrderRecord> list = dlOrderRecordService.selectDlOrderRecordList(dlOrderRecord);
        return getDataTable(list);
    }

    /**
     * 导出订单记录列表
     */
    @RequiresPermissions("mydy:orderrecord:export")
    @Log(title = "订单记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DlOrderRecord dlOrderRecord)
    {
        List<DlOrderRecord> list = dlOrderRecordService.selectDlOrderRecordList(dlOrderRecord);
        ExcelUtil<DlOrderRecord> util = new ExcelUtil<DlOrderRecord>(DlOrderRecord.class);
        return util.exportExcel(list, "订单记录数据");
    }

    /**
     * 新增订单记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单记录
     */
    @RequiresPermissions("mydy:orderrecord:add")
    @Log(title = "订单记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DlOrderRecord dlOrderRecord)
    {
        return toAjax(dlOrderRecordService.insertDlOrderRecord(dlOrderRecord));
    }

    /**
     * 修改订单记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        DlOrderRecord dlOrderRecord = dlOrderRecordService.selectDlOrderRecordById(id);
        mmap.put("dlOrderRecord", dlOrderRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单记录
     */
    @RequiresPermissions("mydy:orderrecord:edit")
    @Log(title = "订单记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DlOrderRecord dlOrderRecord)
    {
        return toAjax(dlOrderRecordService.updateDlOrderRecord(dlOrderRecord));
    }

    /**
     * 删除订单记录
     */
    @RequiresPermissions("mydy:orderrecord:remove")
    @Log(title = "订单记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dlOrderRecordService.deleteDlOrderRecordByIds(ids));
    }
}
